package com.排序算法;

import java.util.Random;

public class 插入排序 {
    public static void insertSort(int arrays[]) {

        for (int i = 1; i < arrays.length; i++) {
            for (int j = i; j > 0; j--) {
                if (arrays[j - 1] > arrays[j]) {
                    int temp = arrays[j - 1];
                    arrays[j - 1] = arrays[j];
                    arrays[j] = temp;
                } else {
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        int arrays[] = new int[100];
        Random random = new Random();
        for (int i = 0; i < arrays.length; i++) {
            arrays[i] = random.nextInt(1000);
        }
        insertSort(arrays);
        System.out.println("冒泡排序算法结果：");
        for (int i = 0; i < arrays.length; i++) {
            if (i % 10 == 0) {
                System.out.println(" ");
            }
            System.out.print(arrays[i] + " ");
        }
    }
    /**
     * 0 2 20 25 26 27 35 47 53 76
     * 86 86 90 107 109 116 121 125 127 132
     * 134 153 166 167 208 212 240 253 277 279
     * 290 309 330 335 351 361 386 390 391 394
     * 396 408 411 412 413 415 433 439 440 448
     * 459 469 476 481 484 496 506 512 521 528
     * 538 570 586 600 601 601 609 610 620 637
     * 643 647 671 705 707 715 750 758 766 790
     * 793 800 815 819 821 834 838 852 866 879
     * 882 889 906 925 929 931 955 963 966 992
     */
}
